package com.example.sherlockzhong.plush_v2.CardBeans;

import com.example.sherlockzhong.plush_v2.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * Created by DosonLeung on 2014/8/25.
 */
public class OrgBean {
    private int length = 0;
    private String[] filepath = {};
    private int imgs = R.drawable.hci;
    private int dels = R.drawable.del;
    private String[] titles = {"HCI", "HCI", "HCI", "HCI", "HCI", "HCI", "HCI", "HCI", "HCI", "HCI", "HCI", "HCI", "HCI", "HCI", "HCI", "HCI"};
    private List<Map<String, Object>> organization_list = new ArrayList<Map<String, Object>>();
    private String[] itemName = {"grid_icon", "grid_title", "del_icon"};
    private int[] itemId = {R.id.grid_img, R.id.grid_title, R.id.del_icon};

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getImgs() {
        return imgs;
    }

    public void setImgs(int imgs) {
        this.imgs = imgs;
    }

    public String[] getTitles() {
        return titles;
    }

    public void setTitles(String[] titles) {
        this.titles = titles;
    }

    public String[] getItemName() {
        return itemName;
    }

    public void setItemName(String[] itemName) {
        this.itemName = itemName;
    }

    public int[] getItemId() {
        return itemId;
    }

    public void setItemId(int[] itemId) {
        this.itemId = itemId;
    }

    public String[] getFilepath() {
        return filepath;
    }

    public void setFilepath(String[] filepath) {
        this.filepath = filepath;
    }

    public void addLength() {
        length++;
    }

    public void deleteLength() {
        length--;
    }

    public List<Map<String, Object>> generateDataList() {
        if (filepath.length != length) {
            for (int i = 0; i < length; i++) {
                Map<String, Object> item = new HashMap<String, Object>();
                item.put("grid_icon", imgs);
                item.put("grid_title", titles[i]);
                item.put("del_icon", dels);
                organization_list.add(item);
            }
            Map<String, Object> item = new HashMap<String, Object>();
            item.put("grid_icon", R.drawable.add);
            item.put("grid_title", "更多关注");
            item.put("del_icon", R.drawable.transparent);
            organization_list.add(item);
            item = new HashMap<String, Object>();
            item.put("grid_icon", R.drawable.minus);
            item.put("grid_title", "取消关注");
            item.put("del_icon", R.drawable.transparent);
            organization_list.add(item);
            return organization_list;
        } else {
            for (int i = 0; i < length; i++) {
                Map<String, Object> item = new HashMap<String, Object>();
                item.put("grid_icon", filepath[i]);
                item.put("grid_title", titles[i]);
                item.put("del_icon", dels);
                organization_list.add(item);
            }
            Map<String, Object> item = new HashMap<String, Object>();
            item.put("grid_icon", R.drawable.add);
            item.put("grid_title", "更多关注");
            item.put("del_icon", R.drawable.transparent);
            organization_list.add(item);
            item = new HashMap<String, Object>();
            item.put("grid_icon", R.drawable.minus);
            item.put("grid_title", "取消关注");
            item.put("del_icon", R.drawable.transparent);
            organization_list.add(item);
            return organization_list;
        }


    }

    public List<Map<String, Object>> generateTransList() {
        if (filepath.length != length) {
            for (int i = 0; i < length; i++) {
                Map<String, Object> item = new HashMap<String, Object>();
                item.put("grid_icon", imgs);
                item.put("grid_title", titles[i]);
                item.put("del_icon", R.drawable.transparent);
                organization_list.add(item);
            }
            Map<String, Object> item = new HashMap<String, Object>();
            item.put("grid_icon", R.drawable.add);
            item.put("grid_title", "更多关注");
            item.put("del_icon", R.drawable.transparent);
            organization_list.add(item);
            item = new HashMap<String, Object>();
            item.put("grid_icon", R.drawable.minus);
            item.put("grid_title", "取消关注");
            item.put("del_icon", R.drawable.transparent);
            organization_list.add(item);
            return organization_list;
        } else {
            for (int i = 0; i < length; i++) {
                Map<String, Object> item = new HashMap<String, Object>();
                item.put("grid_icon", filepath[i]);
                item.put("grid_title", titles[i]);
                item.put("del_icon", R.drawable.transparent);
                organization_list.add(item);
            }
            Map<String, Object> item = new HashMap<String, Object>();
            item.put("grid_icon", R.drawable.add);
            item.put("grid_title", "更多关注");
            item.put("del_icon", R.drawable.transparent);
            organization_list.add(item);
            item = new HashMap<String, Object>();
            item.put("grid_icon", R.drawable.minus);
            item.put("grid_title", "取消关注");
            item.put("del_icon", R.drawable.transparent);
            organization_list.add(item);
            return organization_list;
        }
    }

    public List<Map<String, Object>> changeListToTransparent(List<Map<String, Object>> list) {
        int i = 0;
        for (i = 0; i < length; i++) {
            list.get(i).remove("del_icon");
            list.get(i).put("del_icon", R.drawable.transparent);
        }
        list.remove(i + 1);
        Map<String, Object> item = new HashMap<String, Object>();
        item.put("grid_icon", R.drawable.minus);
        item.put("grid_title", "取消关注");
        item.put("del_icon", R.drawable.transparent);
        list.add(item);
        return list;
    }

    public List<Map<String, Object>> changeListToBeDelete(List<Map<String, Object>> list) {
        for (int i = 0; i < length; i++) {
            list.get(i).remove("del_icon");
            list.get(i).put("del_icon", R.drawable.del);
        }
        return list;
    }

    public List<Map<String, Object>> removeItem(List<Map<String, Object>> list, int index, int length) {
        list.remove(index);
        if (length > 0) {
            Map<String, Object> item = new HashMap<String, Object>();
            item.put("grid_icon", R.drawable.minus);
            item.put("grid_title", "取消关注");
            item.put("del_icon", R.drawable.transparent);
            list.remove(length);
            list.add(item);
        }
        deleteLength();
        return list;
    }
}
